/* eslint-disable vue/no-parsing-error */
<template>
  <div class="common-table">
    <el-table :data="tableData" height="90%" stripe v-loading="config.loading">
      <el-table-column label="序号" width="85">
        <template slot-scope="scope">
          <!-- row代表含的每一项  $index代表索引 从0开始 -->
          <span>{{ (config.page - 1) * 20 + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <!-- :width="item.width ? item.width : 125" 如果要调整表格宽度 -->
      <el-table-column show-overflow-tooltip v-for="item of tableLabel" :key="item.prop" :label="item.label">
        <template slot-scope="scope">
          <span>{{ scope.row[item.prop] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--:current-page.sync="config.page" =》当前页数， 双向绑定  父级页面的page也会跟着更改  -->
    <el-pagination class="pager" layout="prev, pager, next" :total="config.total" :current-page.sync="config.page" @current-change="changePage">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: '',
  props: {
    tableData: Array,
    tableLabel: Array,
    config: Object // 配置
  },
  methods: {
    handleEdit(row) {
      // 表格编辑操作，传给父组件
      this.$emit('edit', row)
    },
    handleDelete(row) {
      // 表格删除操作，传给父组件
      this.$emit('del', row)
    },
    changePage(page) {
      // 点击获取当前的页码
      this.$emit('changePage', page)
    }
  }
}
</script>

<style lang="stylus" scoped>
.common-table
  height: calc(100% - 62px)
  background #ffffff
  position relative
  .pager
    position absolute
    bottom 10px
    right 0
</style>
